package top.abilities.codegeneration;


import top.abilities.util.util.MybatisGeneratorUtil;
import top.abilities.util.util.PropertiesFileUtil;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @Auhtor: abilites
 * @Description 代码生成类
 * @Date: 2017/11/7 14:02
 * @Modified By:
 */
public class Generator {
    // 根据命名规范，只修改此常量值即可
    private static String MODULE = "code_generation_test";
    private static String DATABASE = "code_generation_test";
    private static String TABLE_PREFIX = "";//表映射的前缀一般来说为表模块前缀
    private static String PACKAGE_NAME = "top.abilities.admin.moudle";//报名
    private static String JDBC_DRIVER = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.driver");
    private static String JDBC_URL = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.url");
    private static String JDBC_USERNAME = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.username");
    private static String JDBC_PASSWORD = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.password");
    // 需要insert后返回主键的表配置，key:表名,value:主键名
    private static Map<String, String> LAST_INSERT_ID_TABLES = new HashMap();


    /**
     * 自动代码生成
     * @param args
     */
    public static void main(String[] args) throws Exception {
        Arrays.asList(TABLE_PREFIX.split(",")).forEach(prefix->{
            try {
                MybatisGeneratorUtil.generator(JDBC_DRIVER, JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD, MODULE, DATABASE, prefix, PACKAGE_NAME, LAST_INSERT_ID_TABLES);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        });
    }
}
